﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CoolCode.Controls
{
    public delegate void  Submit(UserControl control);

    public partial class CommonDialog : UserControl
    {
       public UserControl Panel { get; set; }
        
        private Submit onSubmit;

        public CommonDialog(string title, UserControl panel,  Submit onSubmit)
        {
            InitializeComponent();
            this.dialogPanel.Title = title;
            this.Panel = panel;
            this.content.Children.Add(panel);
            this.onSubmit += onSubmit;

            this.dialogPanel.Width = panel.Width + 10;
            this.dialogPanel.Height = panel.Height + 80;

            this.dialogPanel.OnClose += new RoutedEventHandler(this.ClosePanel);
            this.mask.MouseLeftButtonDown += new MouseButtonEventHandler(mask_MouseLeftButtonDown);
            this.submit.Click += new RoutedEventHandler(submit_Click);
        }

        void submit_Click(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
            if (this.onSubmit != null)
                onSubmit(this.Panel);
        }

        public void ClosePanel(object sender, RoutedEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }

        void mask_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }
    }
}
